{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#编写一个函数，判断变量名定义是否变量名定义是否合法：变量名可以由字母 数字 下划线组成变量名只能以字母和或者下划线开头\n",
    "b = \"abcdefghijklmnopqrstuvwxyz\"\n",
    "c =b.upper()\n",
    "d = b+c\n",
    "\n",
    "\n",
    "def hefa(a):\n",
    "    \n",
    "\n",
    "    if a[0]in d or a[0]==\"_\":\n",
    "        if a[1::].isalnum()==True:\n",
    "            return True\n",
    "        else:\n",
    "            \n",
    "            \n",
    "\n",
    "\n",
    "            if a[1::].split(\"_\")[0].isalnum()==True and  a[1::].split(\"_\")[1].isalnum()==True:\n",
    "                return True\n",
    "            else:\n",
    "                return False\n",
    "    else:\n",
    "        return False\n",
    "a = \"ads_5\"\n",
    "\n",
    "\n",
    "\n",
    "hefa(a)\n",
    "        \n",
    "            \n",
    "\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "mi xiao hello\n"
     ]
    }
   ],
   "source": [
    "#给定一个句子（只包含字母和空格）， 将句子中的单词位置反转，单词用空格分割, 单词之间只有一个空格，前>后没有空格。\n",
    "#比如： （1） “hello xiao mi”-> “mi xiao hello”\n",
    "def fan(a):\n",
    "    return \" \".join(a.split()[::-1])\n",
    "a = \"hello xiao mi\"\n",
    "\n",
    "print(fan(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "==============================\n",
      "项目                   价格\n",
      "------------------------------\n",
      "苹果                 6.00\n",
      "桔子                 3.20\n",
      "香蕉                 2.50\n",
      "葡萄                14.80\n",
      "红提                15.00\n",
      "西瓜                 1.50\n",
      "==============================\n"
     ]
    }
   ],
   "source": [
    "'''课后作业\n",
    "编写程序，格式化打印下面购物清单（超市的小票）\n",
    "表格的宽度:30\n",
    "\n",
    "==============================\n",
    "项目                  价格\n",
    "------------------------------\n",
    "苹果                    6.00\n",
    "桔子                    3.20\n",
    "香蕉                    2.50\n",
    "葡萄                   14.80\n",
    "红提                   15.00\n",
    "西瓜                    1.50\n",
    "=============================='''\n",
    "def dy():\n",
    "    print(\"=\"*30)\n",
    "    print('{:<10}'.format(\"项目\"), \" \",'{:>10}'.format(\"价格\"))\n",
    "    print(\"-\"*30)\n",
    "    print('{:<10}'.format(\"苹果\"), \" \",'{: >10.2f}'.format(6))\n",
    "    print('{:<10}'.format(\"桔子\"), \" \",'{: >10.2f}'.format(3.2))\n",
    "    print('{:<10}'.format(\"香蕉\"), \" \",'{: >10.2f}'.format(2.5))\n",
    "    print('{:<10}'.format(\"葡萄\"), \" \",'{: >10.2f}'.format(14.8))\n",
    "    print('{:<10}'.format(\"红提\"), \" \",'{: >10.2f}'.format(15))\n",
    "    print('{:<10}'.format(\"西瓜\"), \" \",'{: >10.2f}'.format(1.5))\n",
    "    print(\"=\"*30)\n",
    "dy()\n"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "221474af6eb59aa5df9a0523b1a7e5113f2b8926bfc82d2e634c0e264e6aff21"
  },
  "kernelspec": {
   "display_name": "Python 3.9.7 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
